#ifndef GATHER_H
#define GATHER_H

/**
 * @copyright Copyright (c) 2025 
 * CSG Digital Grid Technology (Guangdong) Co., Ltd.
 * @author zhouyan
 * @brief 数据采集模块
*/
#include "sys_inc.h"
#include "tools/m_mutex.h"

class IDevice;
class MSem;

class Gather
{
    typedef  std::list<IDevice *> IDevices;
    friend void* gatherThreadProc(void *argv);
public:
    Gather(void);
    ~Gather();

    bool addDevice(IDevice *dev);
    void removeDevice(IDevice *dev);

    void startGather(void* v = nullptr);
    void stopGather(void);

protected:
    void gatherProc(void);

private:
    bool containof(IDevice *dev, const IDevices &devs);

private:
    IDevices active_devices_;
    IDevices inactive_devices_;

    uint32_t poll_cnt_;
    uint32_t retry_after_lost_;
    uint32_t poll_time_ms_;
    bool started_;
    MMutex mtx_;
};

#endif // GATHER_H
